//
//  WSDataReportFullScreenCell.m
//  microvision
//
//  Created by zhenjingxiong on 2021/3/5.
//  Copyright © 2021 tencent. All rights reserved.
//

#import "WSDataReportFullScreenCell.h"
#import "WSDataReportConfig.h"
#import "WSDataReportHelper.h"

@interface WSDataReportFullScreenCell ()

@end

@implementation WSDataReportFullScreenCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor clearColor];
    
    NSArray *array = [WSDataReportConfig instance].listViewShowKeyArray;
    for (int i = 0; i < array.count; i ++) {
        UILabel *listShowLabel = [UILabel new];
        listShowLabel.font = [UIFont systemFontOfSize:13];
        listShowLabel.backgroundColor = [UIColor  greenColor];
        listShowLabel.translatesAutoresizingMaskIntoConstraints = NO;
        [self.contentView addSubview:listShowLabel];
        
        NSLayoutConstraint *textViewLayoutConstraintTop = [NSLayoutConstraint constraintWithItem:listShowLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:20 * i];
        NSLayoutConstraint *textViewLayoutConstraintLeft = [NSLayoutConstraint constraintWithItem:listShowLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:5];
        [self.contentView addConstraints:@[textViewLayoutConstraintTop, textViewLayoutConstraintLeft]];
        
        listShowLabel.text = array[i];
        [self.listShowLableArray addObject:listShowLabel];
    }
    
    UIImageView *separatorLineImageView = [[UIImageView alloc] init];
    separatorLineImageView.translatesAutoresizingMaskIntoConstraints = NO;
    separatorLineImageView.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:separatorLineImageView];

    NSLayoutConstraint *textViewLayoutConstraintHeight = [NSLayoutConstraint constraintWithItem:separatorLineImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:1];
    [separatorLineImageView addConstraint:textViewLayoutConstraintHeight];
    
    NSLayoutConstraint *separatorLineImageViewLeading = [WSDataReportHelper equallyRelatedConstraintWithView:separatorLineImageView toItem:self.contentView attribute:NSLayoutAttributeLeading];
    NSLayoutConstraint *separatorLineImageViewTrailing = [WSDataReportHelper equallyRelatedConstraintWithView:separatorLineImageView toItem:self.contentView attribute:NSLayoutAttributeTrailing];
    NSLayoutConstraint *separatorLineImageViewBottom = [NSLayoutConstraint constraintWithItem:separatorLineImageView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
    [self.contentView addConstraints:@[separatorLineImageViewLeading, separatorLineImageViewTrailing, separatorLineImageViewBottom]];
}


- (void)setShowLabelData:(NSDictionary *)reportDataDictionary {
    NSArray *array = [WSDataReportConfig instance].listViewShowKeyArray;
    for (int i = 0; i < array.count; i ++) {
        UILabel *listShowLabel = self.listShowLableArray[i];
        [self.contentView addSubview:listShowLabel];
        NSString *keyStr = array[i];
        NSString *valueStr = reportDataDictionary[keyStr] ?: @"";
        listShowLabel.text = [NSString stringWithFormat:@"%@:%@",keyStr,valueStr];
    }
}


- (NSMutableArray<UILabel *> *)listShowLableArray {
    if (!_listShowLableArray) {
        _listShowLableArray = [NSMutableArray array];
    }
    return _listShowLableArray;
}

@end
